package com.hongsen.cn.activity;

import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import androidx.databinding.DataBindingUtil;
import androidx.databinding.ObservableInt;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.hongsen.cn.Utils.GridSpacingItemDecoration;
import com.hongsen.cn.Utils.LogUtil;
import com.hongsen.cn.Utils.NumberUtils;
import com.hongsen.cn.Utils.RxBus;
import com.hongsen.cn.Utils.SPUtil;
import com.hongsen.cn.adapter.RefreshFaceAdapter;
import com.hongsen.cn.base.BaseActivity;
import com.hongsen.cn.bean.BaseTitleBean;
import com.hongsen.cn.bean.CheckBean;
import com.hongsen.cn.bean.RxValue;
import com.hongsen.cn.bean.TitleBean;
import com.hongsen.cn.contract.RefreshFaceView;
import com.hongsen.cn.dayandmonth.R;
import com.hongsen.cn.dayandmonth.databinding.ActivityRefreshFaceFroWorkBinding;
import com.hongsen.cn.presenter.RefreshFacePresenter;

import java.util.ArrayList;
import java.util.List;

public class RefreshFaceForWorkActivity extends BaseActivity<RefreshFacePresenter> implements RefreshFaceView {

    public ActivityRefreshFaceFroWorkBinding binding;
    private String type = "10";
    public ObservableInt FBI_INDEX_SELECT = new ObservableInt(0);
    public RefreshFaceAdapter leftFaceAdapter, rightFaceAdapter;
    public List<CheckBean> listLeftBeans = new ArrayList<>();
    public List<CheckBean> listRightBeans = new ArrayList<>();


    @Override
    protected RefreshFacePresenter createPresenter() {
        return new RefreshFacePresenter(this);
    }


    @Override
    protected void initData() {

    }

    @Override
    protected void initView() {

        binding = DataBindingUtil.inflate(LayoutInflater.from(this), R.layout.activity_refresh_face_fro_work, null, false);
        binding.setActivity(this);
        baseFl.addView(binding.getRoot());
        presenter = new RefreshFacePresenter(this);
        //presenter.getTitleInfo();
        TitleBean titleBean = TitleBean.getBean(RefreshFaceForWorkActivity.this);

        if (titleBean != null) {
            LogUtil.e("人脸更多记录发送title数据");

            RxBus.getDefault().post(new RxValue("module_FBI_WG", titleBean.getTitleOne()));
            RxBus.getDefault().post(new RxValue("module_FBI_JD", titleBean.getTitleTwo()));
            RxBus.getDefault().post(new RxValue("module_FBI_JD_CC", titleBean.getTitleThree()));
            RxBus.getDefault().post(new RxValue("module_FBI_DT", titleBean.getTitleFour()));
            RxBus.getDefault().post(new RxValue("module_FBI_CS", titleBean.getTitleFive()));
        } else {
            LogUtil.e("更多记录titleBean== null");

        }


        type = NumberUtils.getStatueByTime();
        switch (type) {
            case "10":
                FBI_INDEX_SELECT.set(0);
                break;
            case "20":
                FBI_INDEX_SELECT.set(1);
                break;
            case "30":
                FBI_INDEX_SELECT.set(2);
                break;
            case "40":
                FBI_INDEX_SELECT.set(3);
                break;
            default:
        }
        presenter.getList(type);


        binding.clRight.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId) {
                    case R.id.rb1:
                        type = "10";
                        break;

                    case R.id.rb2:
                        type = "20";
                        break;

                    case R.id.rb3:
                        type = "30";
                        break;

                    case R.id.rb4:
                        type = "40";
                        break;
                    default:
                        break;

                }
                presenter.getList(type);
            }
        });

        /**
         * 左侧列表
         */
        binding.recyclerViewNormal.setLayoutManager(new GridLayoutManager(RefreshFaceForWorkActivity.this, 2));
        binding.recyclerViewError.setLayoutManager(new GridLayoutManager(RefreshFaceForWorkActivity.this, 2));

        leftFaceAdapter = new RefreshFaceAdapter(RefreshFaceForWorkActivity.this, listLeftBeans);
        rightFaceAdapter = new RefreshFaceAdapter(RefreshFaceForWorkActivity.this, listRightBeans);

        binding.recyclerViewNormal.setAdapter(leftFaceAdapter);
        binding.recyclerViewError.setAdapter(rightFaceAdapter);

        binding.recyclerViewNormal.addItemDecoration(new GridSpacingItemDecoration(10, 10));
        binding.recyclerViewError.addItemDecoration(new GridSpacingItemDecoration(10, 10));

    }

    public void onClick(View v) {
        int sS_ID = v.getId();
        if (sS_ID == R.id.btnBack) {
            finish();
        }
    }

    @Override
    public void getListByTime(List<CheckBean> listBean) {
        listLeftBeans.clear();
        listRightBeans.clear();
        for (CheckBean checkBean : listBean) {
            if (checkBean.getYc().equals("1")) {
                listLeftBeans.add(checkBean);
            } else if (checkBean.getYc().equals("2")) {
                listRightBeans.add(checkBean);
            }
        }
        leftFaceAdapter.notifyDataSetChanged();
        rightFaceAdapter.notifyDataSetChanged();
    }

    @Override
    public void getTitleInfo(BaseTitleBean str) {
        RxBus.getDefault().post(new RxValue("module_FBI_WG", String.valueOf(str.getEffectiveVO().getNissinMonthlyCount())));
        RxBus.getDefault().post(new RxValue("module_FBI_JD", String.valueOf(str.getMechanicalDeviceVo().getNissinMonthlyCount())));
        RxBus.getDefault().post(new RxValue("module_FBI_JD_CC", String.valueOf(str.getMechanicalDeviceVo().getArePersonnelCount())));
        RxBus.getDefault().post(new RxValue("module_FBI_DT", String.valueOf(str.getRiskVO().getNissinMonthlyCount())));
        RxBus.getDefault().post(new RxValue("module_FBI_CS", String.valueOf(str.getOutVO().getNissinMonthlyCount())));
    }
}
